#+TITLE: My Emacs Configuration File
#+AUTHOR: Jose Meraz
#+STARTUP: content

This is my emacs configuration in an org-mode file, very neat and tidy, please keep it like that.

* Performance

#+begin_src emacs-lisp
  (setq gc-cons-threshold 100000000)
  (setq read-process-output-max (* 1024 1024))
  (add-hook 'after-init-hook #'(lambda ()
                                 (setq gc-cons-threshold 800000)))
#+end_src

* Editing Tweaks

#+begin_src emacs-lisp
  (delete-selection-mode 1) ; delete selected text when inserting
  (show-paren-mode 1)       ; highlight pairing parenthesis
  (global-unset-key (kbd "C-z")) ; don't send emacs to the background
  ;; scroll with ctrl+mousewheel like other editors do
  (global-set-key (kbd "<C-wheel-up>") 'text-scale-increase)
  (global-set-key (kbd "<C-wheel-down>") 'text-scale-decrease)
#+end_src

* Visual Tweaks

UI Elements

#+begin_src emacs-lisp
  (visual-line-mode nil)
  (if (fboundp 'menu-bar-mode)
      (menu-bar-mode -1)) ;; hide menu bar
  (if (fboundp 'tool-bar-mode)
      (tool-bar-mode -1)) ;; hide tool bar
  (if (fboundp 'scroll-bar-mode)
      (scroll-bar-mode -1)) ;; hide scroll bar
  (setq linum-format "%4d ") ;; set number lines format
  (add-hook 'prog-mode-hook
            (if (or
                 (not (fboundp 'linum-mode))
                 (and (fboundp 'display-line-numbers-mode) (display-graphic-p)))
                'display-line-numbers-mode 
              'linum-mode)) ;; show line numbers in programming modes
  ;;(global-display-line-numbers-mode)
  (setq frame-title-format '(buffer-file-name "Emacs: %b (%f)" "Emacs: %b"))
#+end_src

My emacs look and feel for every day work.

#+begin_src emacs-lisp
  (use-package doom-themes
    :config 
    (load-theme 'doom-solarized-dark t))
#+end_src

I like to use doom-modeline even tho I don't use doom emacs myself.

#+begin_src emacs-lisp
  (use-package doom-modeline
    :init (doom-modeline-mode 1))
  (setq doom-modeline-hud nil)
  (setq doom-modeline-icon t)
  (setq doom-modeline-major-mode-icon t)
  (setq doom-modeline-major-mode-color-icon t)
#+end_src

Change the font

#+begin_src emacs-lisp
  (set-frame-font "FiraCode Nerd Font 13" nil t)
#+end_src

You don't need to look at anything else than EMACS, so let's make
it fullscreen...

#+begin_src emacs-lisp
  (custom-set-variables
   '(initial-frame-alist (quote ((fullscreen . maximized)))))
#+end_src

* Backups and temporary files

#+begin_src emacs-lisp
  (defconst emacs-tmp-dir (expand-file-name (format "emacs%d" (user-uid)) temporary-file-directory))
  (setq
   backup-by-copying t
   delete-old-versions t
   kept-new-versions 6
   kept-old-versions 2
   version-control t
   auto-save-list-file-prefix emacs-tmp-dir
   auto-save-file-name-transforms `((".*" ,emacs-tmp-dir t))
   backup-directory-alist `((".*" . ,emacs-tmp-dir)))
  (setq create-lockfiles nil)
#+end_src

* User defined functions

#+begin_src emacs-lisp
  (defun mer/reload-config ()
    "This function will reload my configuration file."
    (interactive)
    (load-file user-init-file))

  (defun mer/edit-config ()
    "Easy access to my emacs config."
    (interactive)
    (find-file user-init-file))

  (defun mer/show-full-file-path ()
    "Show the full file name of the current buffer in the minibuffer."
    (interactive)
    (message (concat "File path: " (buffer-file-name))))

  (defun mer/xdg-open ()
    "Open dired file with external program."
    (interactive)
    (setq file (dired-get-file-for-visit))
    (shell-command (concat "xdg-open " (shell-quote-argument file))))

#+end_src

* Packages

Initial setup for use-package.

#+begin_src emacs-lisp
  (require 'package)
  (setq package-enable-at-startup nil)
  (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
  (unless package--initialized (package-initialize))

  (unless (package-installed-p 'use-package)
    (package-refresh-contents)
    (package-install 'use-package))
  (eval-when-compile
    (require 'use-package))
  (setq use-package-always-ensure t)
#+end_src

And now the packages.

** Unsorted packages

Just packages that I liked and installed into Emacs.

*** Undo tree

#+begin_src emacs-lisp
  (use-package undo-tree
    :init (global-undo-tree-mode)
    :config (setq-default undo-tree-auto-save-history nil))
#+end_src

*** Beacon

Highlight the cursor whenever the window scrolls

#+begin_src emacs-lisp
  (use-package beacon
    :init (beacon-mode))
#+end_src

*** Org Superstar

This mode (among other things) adds nice symbols for org-mode headers.

#+begin_src emacs-lisp
  (use-package org-superstar)
  (add-hook 'org-mode-hook (lambda () (org-superstar-mode 1)))
#+end_src

*** Company mode

#+begin_src emacs-lisp
  (use-package company
    :init (global-company-mode t)
    :config
    ;;navigate minibuffer
    (define-key company-active-map (kbd "C-n") 'company-select-next)
    (define-key company-active-map (kbd "C-p") 'company-select-previous)

    ;; Provide instant autocompletion.
    (setq company-idle-delay 0.0))
#+end_src

*** Lorem Ipsum

Aliquam erat volutpat.  Nunc eleifend leo vitae magna.  In id erat non
orci commodo lobortis.  Proin neque massa, cursus ut, gravida ut,
lobortis eget, lacus.  Sed diam.  Praesent fermentum tempor tellus.
Nullam tempus.  Mauris ac felis vel velit tristique imperdiet.  Donec
at pede.  Etiam vel neque nec dui dignissim bibendum.  Vivamus id
enim.  Phasellus neque orci, porta a, aliquet quis, semper a, massa.
Phasellus purus.  Pellentesque tristique imperdiet tortor.  Nam
euismod tellus id erat.

#+begin_src emacs-lisp
  (use-package lorem-ipsum)
#+end_src

** Language support

Packages specific to programming languages.

*** Eglot

This thing connects to language server protocols very easily.

#+begin_src emacs-lisp
  (use-package eglot
    :config (global-set-key [f4] 'eglot))
#+end_src

*** Golang

#+begin_src emacs-lisp
  (use-package go-mode
    :config (add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode)))
#+end_src

*** Lua

#+begin_src emacs-lisp
  (use-package lua-mode
    :config (add-to-list 'auto-mode-alist '("\\.lua\\'" . lua-mode)))
#+end_src

*** Markdown

Ye... Org mode is superior but sometimes I need to pull up a nasty markdown file.

#+begin_src emacs-lisp
  (use-package markdown-mode
    :mode ("README\\.md\\'" . gfm-mode)
    :init (setq markdown-command "multimarkdown"))
#+end_src

*** HTML/CSS

#+begin_src emacs-lisp
  (use-package web-mode
    :config
    (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
    (add-to-list 'auto-mode-alist '("\\.css\\'" . web-mode)))
  (use-package emmet-mode
    :config
    (add-hook 'css-mode-hook  'emmet-mode)
    (add-hook 'web-mode-hook  'emmet-mode))
#+end_src

* Key bindings

Some editing bindings

#+begin_src emacs-lisp
  (global-set-key [mouse-3] 'mouse-popup-menubar-stuff)
  (global-set-key (kbd "C->") 'indent-rigidly-right-to-tab-stop)
  (global-set-key (kbd "C-<") 'indent-rigidly-left-to-tab-stop)
#+end_src

Open this config file with a key stroke.

#+begin_src emacs-lisp
  (global-set-key (kbd "<f6>") (lambda() (interactive)(find-file "~/.emacs.d/")))
#+end_src

Some key bindings for emacs modes and functions

#+begin_src emacs-lisp
  (global-set-key "\C-ce" 'eww)
  (global-set-key "\C-cs" 'eshell)
  (global-set-key "\C-xb" 'ibuffer)
  (global-set-key "\C-ck" 'delete-frame)
  (global-set-key "\C-cc" 'mer/edit-config)
  (global-set-key "\C-cq" 'mer/reload-config)
  (global-set-key "\C-cf" 'mer/show-full-file-path)
  (eval-after-load "dired"
    '(progn (define-key dired-mode-map (kbd "M-o") 'other-window)
            (define-key dired-mode-map (kbd "\C-co") 'mer/xdg-open)))
  (global-set-key "\C-cy" 'yas-insert-snippet)
#+end_src

* The EWW web browser

I find myself using this web browser more often so I figured out I would tweak it a tiny bit.

#+begin_src emacs-lisp
  (setq eww-download-directory "~/Downloads/"
        eww-desktop-remove-duplicates t
        eww-history-limit 20
        eww-search-prefix "https://lite.duckduckgo.com/lite/?q=")
#+end_src
